//index.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
     imgurl:app.urlimg,
    content: [],
    loadHidden:false,
		modal_style: true,
    kd_no:0,
  },
	revise:function(e){
    var that=this
		var index=e.currentTarget.dataset.index;
		if (index==0){
			hint("确定要修改申请吗？", index,that,e)
		}else{
			hint("您将撤销本次申请，如果问题未解决，您还可以再次发起，确定继续吗？", index,that,e)
		}
		function hint(text, num,that,e){
			wx.showModal({
				title: '',
				content: text,
				success: function (res) {
					if (res.confirm) {
						if (num == 0){
							console.log('跳转到退款申请页面')
							wx.redirectTo({
								url: '/pages/account/refund/index?refunds_id='+e.currentTarget.dataset.refunds_id
                +'&order_goods_id='+e.currentTarget.dataset.order_goods_id+'&order_id='+e.currentTarget.dataset.order_id,
							})
						}
						if (num == 1) {
							console.log('跳转到退款/售后详情页面')
                        wx.request({
                        url: app.url + 'api_refunds/cancelRefund',
                        data: {
                          refunds_id:that.data.data.id
                        },
                        header: {
                          'content-type': 'application/json',
                          'token':wx.getStorageSync('token_key')
                        }, success: function (json) {
                          console.log(json)
                          if(json.data.done){
                           wx.navigateBack({ delta: '' })                                                 
                          }else{
                            app.apperror(json);
                          }
                        }
                      })
						}
					}
				}
			})
		}
	},
	// 输入物流号
	calling: function () {
		this.setData({
			code: true,
		})
	},
	remove: function () {
		this.setData({
			code: false,
		})
	},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
  wx.request({
                        url: app.url + 'api_refunds/refund_detail',
                        data: {
                          refunds_id:options.refunds_id
                        },
                        header: {
                          'content-type': 'application/json',
                          'token':wx.getStorageSync('token_key')
                        }, success: function (json) {
                          console.log(json)
                          if(json.data.done){
                            var data= json.data.result
                             that.setData({
                                 data:data,
                                 loadHidden:true,
                                 kd_no:data.kd_no,
                                    });                                                       
                          }else{
                            app.apperror(json.data.message);
                          }
                            
                        }
                      })
  },
  bindFormSubmit: function(e) {
    var that = this
console.log(e.detail.value.kd_no);
  if(!e.detail.value.kd_no){
 wx.showModal({
         title: '提示',
         content: '输入正确的快递单号',
         success: function (res) {
           if (res.confirm) {
           
           }
         }
       })
        return false
   }
      wx.request({
                        url: app.url + 'api_refunds/kdNo',
                        data: {
                          kd_no:e.detail.value.kd_no,
                            refunds_id:that.data.data.id
                        },
                        header: {
                          'content-type': 'application/json',
                          'token':wx.getStorageSync('token_key')
                        }, success: function (json) {
                          console.log(json)
                          if(json.data.done){
                          that.setData({modal_style:true,kd_no:e.detail.value.kd_no})                                     
                          }else{
                            app.apperror(json);
                          }
                        }
                      })








},
bindFormreset:function(){
	this.setData({modal_style:true})
},
showKDno:function(){
	this.setData({modal_style:false})
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})